<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>昨日涨停股今日主力排名</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">									
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
			width:460px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>		
		<script>
		
			var day = new Date();			
			var tt = "";
			var tt1 = "";					
			window.onload = function() {								
			getSource();			
			changeStyle();					
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource1();				
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {					
				time_range("9:00","15:15")																
				},
				60000);
			})
			
			function changeStyle() {
				var obj = document.getElementById("towrite");				
				obj.style.left= "0px"; 				
				obj.style.width= "480px";	
				obj.style.height= "620px";		
				obj.style.fontSize="12px";			
			}					
					
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			<!-- var trid = ""; -->
			<!-- function changeCss(obj,hid,id){						 -->
				<!-- var tlist = document.getElementById(id).getElementsByTagName("tr");					 -->
				<!-- for(var i = 0; i < tlist.length; i++){														 -->
					<!-- tlist[i].style.backgroundColor = "#252528"; 					 -->
				<!-- } -->
				<!-- trid = hid; -->
				<!-- var tr = document.getElementById(hid);				 -->
				<!-- tr.style.backgroundColor = "#483D8B";						 -->
			<!-- } -->
			
			var trid = "";
			var trs = "";
			function changeCss(obj,id){	
				trs = "";
				var t = obj.parentNode.parentNode.id;  //td父节点tr id
				var ty = t.split("#")[1];			
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){
					var dm = tlist[i].id.split("#")[0];
					var yy = tlist[i].id.split("#")[1];					
					if(t == tlist[i].id){
						tlist[i].style.backgroundColor = "#483D8B";  //选中行
						trid = t;
					}else if(ty == yy){
						tlist[i].style.backgroundColor = "#800080"; //相同涨停原因
						trs += tlist[i].id;
					}else{
						tlist[i].style.backgroundColor = "#252528"; 				
					}						
				}				
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){				
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";							
						}
					}
					rows[i].onmouseout=function(){						
						if(this.id != ""){  //过滤表头
							if(this.id == trid){  //过滤选中行
								this.style.background="#483D8B";
							}else if(trs.indexOf(this.id) > -1){
								this.style.background="#800080";
							}else{
								this.style.background="#252528";
							}
						}						
					}					
				}
			}			
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function UnUnicode(str) {
				return unescape(str.replace(/\\/g, "%"));
			}
			
			function getSource() {							
				var url = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&ZSType=7&"; 
				if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();				
				} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");						
				}				
				xmlHttp1.onreadystatechange = writeSource;
				xmlHttp1.open("GET", url, true);
				xmlHttp1.send(null);				
			}
									
			function writeSource() { 
				if (xmlHttp1.readyState == 4) { 																		
					var data1 = xmlHttp1.responseText									
					if(tt1 == "")
					{
						//tt1 = data1.match(/\"Day\":\[\"(\S*)\"\],/)[1];
						tt1 = data1.match(/"Day":\["(\S*)/)[1].split('"]')[0];
						//t = tt1.split("-");
						//day = new Date(t[0], t[1]-1, t[2]);	
						day = new Date(tt1);							
						gethisdate(); //推算前个交易日
					}								
				}					
			}
			
			function gethisdate() {
				day.setTime(day.getTime());				
				for (i = 1; i < 100; i++){	//节假日																										
					day.setTime(day.getTime() - 24*60*60*1000);
					tt = day.Format("yyyy-MM-dd");				
					//alert(tt);
					//var url = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=20&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=1&Day=" + tt + "&";
					var url = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&ZSType=7&Date=" + tt; 
					var xhr = new XMLHttpRequest();	
					xhr.open("GET", url, false);//同步 
					xhr.send(null)																										
					var data = xhr.responseText;					
					if(data.indexOf("MYSQL数据库链接出错!") == -1 && data.indexOf("\"list\":\[\]") == -1)	
					{
						//alert(tt);						
						//tt1 = tt;											
						//gt = day.getDate();
						break;						
					}
				}
				//alert(tt1);
				for (j = 1; j < 6 ; j++)
				{
					getSourcehis(j.toString());
				}					
			}
			
			var data1 = "";
			function getSourcehis(ss) {							
				var url1 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=5&Day=" + tt + "&";
				var url2 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=4&Day=" + tt + "&";
				var url3 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=3&Day=" + tt + "&"; 				
				var url4 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=2&Day=" + tt + "&";
				var url5 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=1&Day=" + tt + "&";
				
				var url = "";
				var bt = "";
				if(ss == "1"){
					url = url1;					
					bt = "四板以上：";
				}
				if(ss == "2"){
					url = url2;					
					bt = "四板：";
				}
				if(ss == "3"){
					url = url3;					
					bt = "三板：";
				}
				if(ss == "4"){
					url = url4;					
					bt = "二板：";
				}
				if(ss == "5"){
					url = url5;					
					bt = "一板：";
				}
				
				var xmlHttp = new XMLHttpRequest();					
				xmlHttp.open("GET", url, false);  //同步方式
				xmlHttp.send(null);				
			    
				var data = xmlHttp.responseText
				//document.write(data);
				data = data.replace("\[\[\]","\[\]");
				//alert(data);
				var html = "";
				if (data.indexOf('\"' + 'info' + '\"' + ':\[\]') == -1 ) { 
					data = data.replace(/ /g,"").match(/(\S*)\]\],\"/)[1] + ']]';												
					data = data.replace(/(\[\").*?(?=\])/g,function(word){ str = word.match(/\[(\S*)/)[1]; 
					return '{"code":' + str.split(',')[0] + 
					',"name":' + str.split(',')[1] + 
					',"zttime":'+str.split(',')[4] + 
					',"ztyy":'+str.split(',')[5] + 
					',"je":'+str.split(',')[8] + 
					',"lb":'+str.split(',')[15] + 
					',"lbs":'+str.split(',')[18];});
					data = data.replace(/\[\[\{/g,'[{').replace(/\]\]/g,"}]}").replace(/],{/g,"},{");
					//时间				
					data = data.replace(/(\"zttime\":).*?(?=,)/g, function(word){ 						
					str = word.match(/\"zttime\":(\S*)/)[1]; 					
							return '\"zttime\":\"' + getLocalTime(str) + '\"';					
					});  	 			
					//净额				
					data = data.replace(/(\"je\":).*?(?=,)/g, function(word){ 						
					str = word.match(/\"je\":(\S*)/)[1]; 					
							if(keepTwoDecimal(Math.abs(str/100000000)) >= 1)
							{
								return '\"je\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"je\":\"' + Math.round(str/10000) + '万\"';
							}					
					});	
									
					//document.write(data);
					var ss1 = data.split('},{');				
					for (i = 0; i < ss1.length; i++)					
					{					
						var code = ss1[i].match(/\"code\":\"(\S*)\",\"name/)[1];						
						var name = ss1[i].match(/\"name\":\"(\S*)\",\"zttime/)[1];
						var lb = ss1[i].match(/\"lb\":(\S*),\"/)[1];
						data1 +=  '{' + '\"code\":"' + code + '",\"name\":"' + name + '",\"lb\":' + lb + "},";
					}
					
					//document.write(data1);					
					getSource1();
				}							
			}
			
			function getSource1() {			
				data2 = "";
				div = document.getElementById('towrite');														
				div.innerHTML = "<font size='3'><strong>昨日涨停股今日主力排名</strong></font><br><br>";	
				var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112308980107330704572_1632445353427&fid=f184&po=1&pz=5000&pn=1&np=1&fltt=2&invt=2&fields=f2,f3,f12,f14,f100,f184,f225&ut=b2884a393a59ad64002292a3e90d46a5&fs=m:0+t:6+f:!2,m:0+t:13+f:!2,m:0+t:80+f:!2,m:1+t:2+f:!2,m:1+t:23+f:!2"; 	                							
				if (window.XMLHttpRequest) {
				xmlHttp2 = new XMLHttpRequest();				
				} else {
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");						
				}				
				xmlHttp2.onreadystatechange = writeSource1;
				xmlHttp2.open("GET", url, true);
				xmlHttp2.send(null);				
			}
			
			var data2 = "";	
			function writeSource1() { 
				if (xmlHttp2.readyState == 4 ) {         
					var data = xmlHttp2.responseText						
					data = data.replace(/ /g,"").match(/\"diff\":(\S*)\}\]\}\}\);/)[1];	
					data = "{\"data\":" + data + "}]}";
					//document.write(data);
					
					var ss1 = data1.split('},{');
									
					for (i = 0; i < ss1.length; i++)					
					{											
						var code = ss1[i].match(/\"code\":\"(\S*)\",\"name/)[1];						
						if(data.indexOf(code) > -1)
						{
							var reg = data.replace(new RegExp(code,'g'),"abcde");							
							var aa = reg.match(/abcde(\S*)/)[1];
							var bb = reg.match(/(\S*)abcde/)[0];
							//alert(bb);
							var ss = bb.split('{');
							aa1 = ss[ss.length - 1];
							aa1 = aa1.replace(",\"f12\":\"abcde","");
							
							if(aa.indexOf("}") > -1)
							{
								aa2 = aa.substring(0 , aa.indexOf("}"));	
							}							
							aa2 = aa2.match(/,\"f100\":(\S*)/)[1];							
							data2 += "{" + ss1[i] + "," + aa1 + ',"f100":' + aa2 + "},";
						}						
					}					
					data2 = (data2 + "]").replace("},,",",").replace("},]","}]").replace("{{","[{");
					//document.write(data2);
					//alert(data2)
					
					var json = JSON.parse(data2);
					
					//排序							
					function up(a,b){						
						return b.f184 - a.f184
					}					
					json.sort(up);
					
					//创建table					
					var table=document.createElement("table");										
					var thead=document.createElement("thead");
					table.appendChild(thead);					
					var tr=document.createElement("tr");
					thead.appendChild(tr);					
					
					var m = 0;
					var n = 0;					
					var b = 0;
					var gl = "主力净占比";  //高亮
					for(var key in json[0]){  //表头
						key = key.replace('f225','排名').replace('code','代码').replace('name','名称').replace('f3','涨幅%').replace('f2','现价');
						key = key.replace('f184','主力净占比%').replace('f100','板块').replace('lb','连板');					
						
						var th=document.createElement("th");						
						th.innerHTML=key;						
						tr.appendChild(th);	
						if(gl == key.replace("%","")){
							n = m;
							th.style.color = "#FF6633";	
						}						
						if(key == "板块"){
							b = m;
							th.style.color = "#FFA500";	
						}
						m++;
					}
										
					var tbody=document.createElement("tbody");					
					table.appendChild(tbody);
					
					//遍历json
					for(var i = 0; i < json.length; i++){					
						var tr=document.createElement("tr");						
						var p = 1;
						var dm = "";
						var mc = "";
						for(var key in json[i]){ //行元素遍历						
							var td=document.createElement("td");							
							
							var rc = json[i][key];
							if(p == 1){  //代码列
								dm = rc;
								tr.id = dm;
							}else if(p == b + 1){
								zt = rc;
								tr.id = dm + "#" + zt;
							}					
							//td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
							td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"gg\")'>" + rc + "</a>";

							if(p == n + 1){							
								td.getElementsByTagName("a")[0].style.color = "#FF6633";
							}							
							if(p == b + 1){							
								td.getElementsByTagName("a")[0].style.color = "#FFA500";								
							}							
							tr.appendChild(td);
							p++;
						}						
						tbody.appendChild(tr);
					}					
					var div = document.getElementById("towrite");									
					div.appendChild(table);
					table.id = "gg";
					
					var table=document.getElementsByTagName("table")[0];
					makeSortable(table);
					hover();					
				}
			}
			
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);						
							showCol(n);		//高亮
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("板块") != -1){
									val1 = val1;
									val2 = val2;
								}else{
									if(val1 == "-"){
										val1 = " ";
									}
									if(val2 == "-"){
										val2 = " ";
									}
									val1 = val1.replace(" ","0").replace("无","1000").replace("NaN","0");
									val2 = val2.replace(" ","0").replace("无","1000").replace("NaN","0");
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
							});
							if(flag){
								rows.reverse();
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;
						}
					}(i));
				}
			}
			
			function showCol(iCol){			
				var oTable = document.getElementsByTagName('table')[0];
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						oTable.rows[i].cells[j].style.color = "#d2d2d3";
						
						oTable.rows[i].cells[5].style.color = "#FFA500"; 										
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}

				otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = "#d2d2d3";
					if(otagsA[i].id == 6){
						otagsA[i].style.color = "#FFA500";								
					}
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}								
			}
			
			<!-- function hover(){  //鼠标经过 -->
				<!-- var rows = document.getElementsByTagName('tr'); -->
				<!-- for(var i=0;i<rows.length;i++){ -->
					<!-- rows[i].onmouseover=function(){						 -->
						<!-- if(this.id != ""){  //过滤表头 -->
							<!-- this.style.background="#800000"; -->
						<!-- } -->
					<!-- } -->
					<!-- rows[i].onmouseout=function(){ -->
						<!-- if(this.id != ""){  //过滤表头 -->
							<!-- if(this.id != trid){  //过滤选中行 -->
								<!-- this.style.background="#252528"; -->
							<!-- }else{ -->
								<!-- this.style.background="#483D8B"; -->
							<!-- } -->
						<!-- }						 -->
					<!-- }					 -->
				<!-- } -->
			<!-- }			 -->
		</script>
	</head>
	<body>							
		<div id="towrite" class="fixedBox"></div>							
	</body>
</html>